/*
 * @lc app=leetcode.cn id=53 lang=javascript
 *
 * [53] 最大子数组和
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxSubArray = function (nums) {
  let sum = nums[0];
  let pre = 0;

  for (const value of nums) {
    pre = Math.max(pre + value, value);
    sum = Math.max(pre, sum);
  }

  return sum;
};
// @lc code=end
